#pragma once

// #define		WM_MSG_SCROLLCHANGED	 WM_USER+200

//#define		SIZE_SCROLL				16

struct SCSBSKin{
	Image*	pImgThunk;					//滚动条路径
	Image*	pImgThumbCenterNormal;		//滑动器位置处于中间时
	Image*	pImgThumbCenterClick;		//滑动器位置处于中间时
	Image*	pImgThumbOriginNormal;		//滑动器位置处于左端/顶端时
	Image*	pImgThumbOriginClick;		//滑动器位置处于左端/顶端时
	Image*	pImgThumbEndNormal;			//滑动器位置处于右端/底端时
	Image*	pImgThumbEndClick;			//滑动器位置处于右端/底端时
	Image*	pImgPageUpAllowNormal;		//向前翻页箭头
	Image*	pImgPageUpAllowClick;		//向前翻页箭头
	Image*	pImgPageDownAllowNormal;	//向后翻页箭头
	Image*	pImgPageDownAllowClick;		//向后翻页箭头


	SCSBSKin(){
		pImgThunk = NULL;				
		pImgThumbCenterNormal = NULL;	
		pImgThumbCenterClick = NULL;	
		pImgThumbOriginNormal = NULL;	
		pImgThumbOriginClick = NULL;	
		pImgThumbEndNormal = NULL;		
		pImgThumbEndClick = NULL;	
		pImgPageUpAllowNormal = NULL;	
		pImgPageDownAllowNormal = NULL;
		pImgPageUpAllowClick = NULL;
		pImgPageDownAllowClick = NULL;
	}
	~SCSBSKin(){
		Release();
	}
	void Release(){
#define RELEASE_IMG(p)	{if(p){delete p;p = NULL;}}
		RELEASE_IMG(pImgThunk);
		RELEASE_IMG(pImgThumbCenterNormal);
		RELEASE_IMG(pImgThumbCenterClick);
		RELEASE_IMG(pImgThumbOriginNormal);
		RELEASE_IMG(pImgThumbOriginClick);
		RELEASE_IMG(pImgThumbEndNormal);
		RELEASE_IMG(pImgThumbEndClick);
		RELEASE_IMG(pImgPageUpAllowNormal);
		RELEASE_IMG(pImgPageDownAllowNormal);
		RELEASE_IMG(pImgPageUpAllowClick);
		RELEASE_IMG(pImgPageDownAllowClick);
	}
};

class CComScrollBarCtrl : public CStatic
{
public:
	CComScrollBarCtrl();
	virtual ~CComScrollBarCtrl();
	
public:
	static BOOL InitSkin(CString szSkinFolder);
	static BOOL ReleaseSkin();

	BOOL ResetSkin_Owner(CString szSkinFolder);
	BOOL RelaseSkin_Owner();

	BOOL InitScrollBar(CWnd *pCtrl, UINT nStyle);
	void UpdateScrollBar();

    void SetScrollBkColor(COLORREF clrScrollBk);

protected:
	afx_msg void OnPaint();
	afx_msg LRESULT OnScrollChanged(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()

private:
	static BOOL	InitVertSKin(CString szSkinFolder);
	static BOOL	InitHorzSKin(CString szSkinFolder);
    BOOL    InitOwnerVertSKin(CString szSkinFolder);
    BOOL    InitOwnerHorzSKin(CString szSkinFolder);

	void	    DrawVScroll(CDC* pDC);
	void	    DrawHScroll(CDC* pDC);
	
	void	    DrawTrack( CDC* pDC, CRect rect, Image* pImage, UINT nBarType);
	void	    DrawThumb( CDC* pDC, CRect rect, Image* pImage, UINT nBarType);
    void        DrawThumbVertBorderAndLine(CDC* pDC);
    void        DrawThumbHorzBorderAndLine(CDC* pDC);
	void	    DrawAllow( CDC* pDC, CRect rect, Image* pImage, UINT nBarType);
	BOOL	    DrawImageByTMB( CDC* pDC, CRect rect, Image* pImage);
	BOOL	    DrawImageByLMR( CDC* pDC, CRect rect, Image* pImage);
private:
	static SCSBSKin	m_skinVert;
	static SCSBSKin	m_skinHorz;
    SCSBSKin*	m_pOwnerSkinVert;
    SCSBSKin*	m_pOwnerSkinHorz;

	CWnd*		m_pCtrl;
	UINT	    m_nScrollStyle;
	BOOL	    m_bThumbClicked;
	BOOL	    m_bCursorOnThumb;

	CSize		m_sizeScroll;
    COLORREF	m_clrScrollBk;

	CRect		m_rcThumb;

	BOOL	    m_bPageDown;
	BOOL	    m_bPageUp;
	BOOL	    m_bPageLeft;
	BOOL	    m_bPageRight;

    COLORREF    m_clrBorderColor;
    COLORREF    m_clrTBBorder;
    CRect       m_rcThumbHorzLine;  //滚动条滑块的三条横线
    CRect       m_rcThumbBorder;    //滑块上下边界
    int         m_iSrcollSize;

};
